import axios from 'axios'
import { showToast } from 'vant'

const request = axios.create({
  baseURL: 'https://geek.itheima.net/'
})

request.interceptors.request.use(
  (config) => {
    try {
      // geek.queryUser() 目前会有警告
      const user = geek.queryUser()
      if (user.token) {
        config.headers.Authorization = `Bearer ${user.token}`
      }
    } catch (e) {
      showToast({ message: '极客园异常' })
    }

    console.log(config.data)

    return config
  },
  (err) => {
    Promise.reject(err)
  }
)

export { request }